

var statusChartData=[
    {
        name:'gaolu',
        series:[
            {name:'高炉预测',type:'line',lineStyle:'dotted',color:'#00ccfe'},
            {name:'高炉历史',type:'line',lineStyle:'solid',color:'#00ccfe'}
        ]
    },
    {
        name:'refenglu',
        series:[
            {name:'热风炉预测',type:'line',lineStyle:'dotted',color:'#00ccfe'},
            {name:'热风炉历史',type:'line',lineStyle:'solid',color:'#00ccfe'}
        ]
    },
    {
        name:'zhagang',
        series:[
            {name:'轧钢预测',type:'line',lineStyle:'dotted',color:'#00ccfe'},
            {name:'轧钢历史',type:'line',lineStyle:'solid',color:'#00ccfe'}
        ]
    },
    {
        name:'other',
        series:[
            {name:'其他预测',type:'line',lineStyle:'dotted',color:'#00ccfe'},
            {name:'其他历史',type:'line',lineStyle:'solid',color:'#00ccfe'}
        ]
    },
    {
        name:'guolu',
        series:[
            {name:'锅炉预测',type:'line',lineStyle:'dotted',color:'#00ccfe'},
            {name:'锅炉历史',type:'line',lineStyle:'solid',color:'#00ccfe'}
        ]
    }

];
var  gasOption=[
    {
        tooltip:{
            show:true,
            formatter:function(params){
                var nameArr = [];
                var valueArr = [];
                var str = '';
                for(var i=0;i<params.length;i++){
                    nameArr[i]=params[i].seriesName;
                    valueArr[i]=Number(params[i].data).toFixed(1);

                    str+= nameArr[i]+' : '+valueArr[i]+'<br/>'
                }
                return str
            }
        },
        dataZoom: [{
            type: 'inside',
            start: 0,
            end: 100
        }],
        grid:{
            left:50,
            top:60,
            right:30,
            bottom:50
        },
        yAxis:{
            scale: true,
            name:'X10⁴',
            axisLabel:{
                formatter:function (value, index) {
                    return (Number(value)/Math.pow(10,4)).toFixed(1);
                }
            }
        }
    },
	{
        tooltip:{
            show:true,
            formatter:function(params){
                var nameArr = [];
                var valueArr = [];
                var str = '';
                for(var i=0;i<params.length;i++){
                    nameArr[i]=params[i].seriesName;
                    valueArr[i]=Number(params[i].data).toFixed(1);

                    str+= nameArr[i]+' : '+valueArr[i]+'<br/>'
                }
                return str
            }
        },
        grid:{
            left:50,
            top:60,
            right:30,
            bottom:50
        },
        dataZoom: [{
            type: 'inside',
            start: 0,
            end: 100
        }],
        yAxis:{
            name:'X10⁴',
            scale: true,
            axisLabel:{
                formatter:function (value, index) {
                    return (Number(value)/Math.pow(10,4)).toFixed(1);
                }
            }
        }
    },
    {
        tooltip:{
            show:true,
            formatter:function(params){
                var nameArr = [];
                var valueArr = [];
                var str = '';
                for(var i=0;i<params.length;i++){
                    nameArr[i]=params[i].seriesName;
                    valueArr[i]=Number(params[i].data).toFixed(1);

                    str+= nameArr[i]+' : '+valueArr[i]+'<br/>'
                }
                return str
            }
        },
        grid:{
            left:50,
            top:60,
            right:30,
            bottom:50
        },
        dataZoom: [{
            type: 'inside',
            start: 0,
            end: 100
        }],
        yAxis:{
            scale: true,
            name:'X10⁴',
            axisLabel:{
                formatter:function (value, index) {
                    return (Number(value)/Math.pow(10,4)).toFixed(1);
                }
            }
        }
    },
    {
        tooltip:{
            show:true,
            formatter:function(params){
                var nameArr = [];
                var valueArr = [];
                var str = '';
                for(var i=0;i<params.length;i++){
                    nameArr[i]=params[i].seriesName;
                    valueArr[i]=Number(params[i].data).toFixed(1);

                    str+= nameArr[i]+' : '+valueArr[i]+'<br/>'
                }
                return str
            }
        },
        grid:{
            left:50,
            top:60,
            right:30,
            bottom:50
        },
        dataZoom: [{
            type: 'inside',
            start: 0,
            end: 100
        }],
        yAxis:{
            name:'X10⁴',
            scale: true,
            axisLabel:{
                formatter:function (value, index) {
                    return (Number(value)/Math.pow(10,4)).toFixed(1);
                }
            }
        }
    },
    {
        tooltip:{
            show:true,
            formatter:function(params){
                var nameArr = [];
                var valueArr = [];
                var str = '';
                for(var i=0;i<params.length;i++){
                    nameArr[i]=params[i].seriesName;
                    valueArr[i]=Number(params[i].data).toFixed(1);
                    str+= nameArr[i]+' : '+valueArr[i]+'<br/>'
                }
                return str
            }
        },
        grid:{
            left:50,
            top:60,
            right:30,
            bottom:50
        },
        dataZoom: [{
            type: 'inside',
            start: 0,
            end: 100
        }],
        yAxis:{
            name:'X10⁴',
            type: 'value',
            scale: true,
            axisLabel:{
                formatter:function (value, index) {
                    return (Number(value)/Math.pow(10,4)).toFixed(1);
                }
            }
        }
    }
];
var APP = new Vue({
    el:'#app',
    data:{
        classlist:['main-item-gaolu','main-item-refenglu','main-item-zhagang','main-item-others','main-item-guolu'],
        name:['高炉','热风炉','轧钢','其他设备','锅炉'],
        statusChartId:['chart_'+uuid(8,64),'chart_'+uuid(8,64),'chart_'+uuid(8,64),'chart_'+uuid(8,64),'chart_'+uuid(8,64)],
        statusChart:[],
        statusObj:{},
        historyData:{},
        PressureData:{},
        //消息中心
        msgCenter:[],
        msgType:'all',
        srcline:'html/history.html',
        gasData:{},
        gasArr:['gaolu','refenglu','zhagang','other','guolu'],
        timeStamp:0,
        linkList:[
            {link:'html/gaolu.html',title:'高炉'},
            {link:'html/hotwind.html',title:'热风炉'},
            {link:'html/zhagang.html',title:'轧钢'},
            {link:'html/guolu.html',title:'锅炉'},
            {link:'html/dongdiao.html',title:'动调'},
            {link:'html/other.html',title:'其他部门'}
        ],
        isOpen:false,
        analysisList:[
            {link:'html/analysis_hotwind.html',title:'煤气平衡'},
            {link:'html/analysis_zhagang.html',title:'轧钢质量'}
        ],
        museOpen:false,
        BaselineData:{},
        refengluStatus:false,
        gaoluStatus:false,
        zhagangStatus:false,
        guoluStatus:false,
        otherStatus:false,
        refengluStatusY:false,
        gaoluStatusY:false,
        zhagangStatusY:false,
        guoluStatusY:false,
        otherStatusY:false,
        username:'',
        showBok: true
    },
	filters:{
        formatterVal:function(val){
            return val/Math.pow(10,4);
        },
        keepInteger:function(val){
            return Math.floor(val);
        },
        keepOne:function(val){
            return val.toFixed(1);
        },
        keepTwo:function(val){
            return Number(val).toFixed(2);
        },
        orNaN:function(val){
            if(isNaN(val)==true){
                return '0.0'
            }else{
                return val
            }
        },
        formatterTime:function(val){
            var oDate=new Date(val);
            var year=oDate.getFullYear();
            var month=oDate.getMonth()+1;
            var date=oDate.getDate();
            var hour=oDate.getHours();
            var minute=oDate.getMinutes();
            return year+'年'+toDou(month)+'月'+toDou(date)+'日  '+toDou(hour)+':'+toDou(minute);
        }

	},
	mounted:function(){
    	var _this = this;
        this.getPressureData();
    	this.getJson();
        this.waveChart();
        this.getName();
    	this.$nextTick(function(){
    		setTimeout(function(){
    			_this.instatusChart();
    			_this.loadStatusChartHistoryData();
                _this.loadStatusChartRealData();
                _this.getPressureData();
			},2000);
    		setInterval(function(){
    			_this.loadStatusChartRealData();
    			//消息中心
                _this.getMsgCenter();
                _this.getJson();
                //状态
               _this.getPressureData();
                _this.waveChart();
			},3000);
            _this.getTimeStamp();
            setInterval(function(){
                _this.getTimeStamp();
            },1000*60)
		})
	},
    methods:{
        //判断波动归因显示隐藏
        BOK:function(){
            this.showBok = !this.showBok
            console.log('1')
        },
        instatusChart:function(){
            var _this = this;
            _this.statusChartId.forEach(function(item,index){
                var _index = index;
                _this.statusChart[index]= new Chart(item,{
                    data:statusChartData[_index].series,
                    baseOption:gasOption[_index],
                })
            });
            //console.log(this.statusObj)
        },
        getSeriesName:function(progress,type){
            var seriesName='';
            if(type=='history' || type=='realPoint'){
                switch(progress){
                    case 'gaolu':
                        seriesName='高炉历史';
                        break;
                    case 'refenglu':
                        seriesName='热风炉历史';
                        break;
                    case 'zhagang':
                        seriesName='轧钢历史';
                        break;
                    case 'other':
                        seriesName='其他历史';
                        break;
                    case 'guolu':
                        seriesName='锅炉历史';
                        break;
                }
            }else if(type=='prediction'){

                switch(progress){
                    case 'gaolu':
                        seriesName='高炉预测';
                        break;
                    case 'refenglu':
                        seriesName='热风炉预测';
                        break;
                    case 'zhagang':
                        seriesName='轧钢预测';
                        break;
                    case 'other':
                        seriesName='其他预测';
                        break;
                    case 'guolu':
                        seriesName='锅炉预测';
                        break;
                }
            }

            return seriesName;
        },
        getStatusChartData:function(progress,type,index){
            var success = function (res) {
                var _this= this;
                var data = res.data;
                var seriesName =_this.getSeriesName(progress,type)
                var axis = getAxis(data);
                if(type=='prediction'){
                    if(axis.dataX.length==0) return;
                    _this.statusChart[index].loadX(axis.dataX)
                }
                if(type=='history'){
                    _this.historyData[progress+'_'+type]=data;
                }
                if(type=='baseLine'){
                    if(data.length==0) return;//调代码
                    _this.BaselineData[progress]=data;//获取基线值
                    _this.statusChart[index].loadBaseLine(seriesName,{
                        data:data
                    })
                }
                if(type=='realPoint'){
                    if(!_this.historyData[progress+'_history']) return;
                    _this.historyData[progress+'_history'].push(data);
                    _this.historyData[progress+'_history'].shift();
                    axisreal = getAxis(_this.historyData[progress+'_history']);
                    //_this.statusChart[index].loadX(axisreal.dataX);
                    _this.statusChart[index].loadData(seriesName,axisreal.dataY)
                }else{
                    _this.statusChart[index].loadData(seriesName,axis.dataY)
                }
            };
            var error = function(e){
                console.log('加载'+type+'图表出错了')
            };
            this.$http.get(URL+'/quanwang/'+progress+'/'+type).then(success,error);
        },
        loadStatusChartHistoryData:function(){
            for(var i=0;i<statusChartData.length;i++){
                var name=statusChartData[i].name;
                this.getStatusChartData(name,'history',i);
                this.getStatusChartData(name,'baseLine',i);
            }
        },
        loadStatusChartRealData:function(){
            for(var i=0;i<statusChartData.length;i++){
                var name=statusChartData[i].name;
                this.getStatusChartData(name,'prediction',i);
                this.getStatusChartData(name,'realPoint',i);
            }
        },
		getPressureData:function(){
        	var _this = this;
        	var success = function(res){
        		 _this.PressureData=res.data;
        		 if(_this.BaselineData.hasOwnProperty("guolu")&&_this.BaselineData.hasOwnProperty("refenglu")&&_this.BaselineData.hasOwnProperty("zhagang")&&_this.BaselineData.hasOwnProperty("other")){
                     if(_this.PressureData.gaolu.current>_this.BaselineData.gaolu.maxVal){
                         _this.gaoluStatus = true;
                         _this.gaoluStatusY = false;
                     }else if(_this.PressureData.gaolu.current<_this.BaselineData.gaolu.minVal){
                        _this.gaoluStatusY = true;
                         _this.gaoluStatus = false;
                     };
                     if(_this.PressureData.refenglu.current>_this.BaselineData.refenglu.maxVal){
                         _this.refengluStatus = true;
                         _this.refengluStatusY = false;
                     }else if(_this.PressureData.refenglu.current<_this.BaselineData.refenglu.minVal) {
                        _this.refengluStatusY = true;
                         _this.refengluStatus = false;
                     };
                     if(_this.PressureData.zhagang.current>_this.BaselineData.zhagang.maxVal){
                         _this.zhagangStatus = true;
                         _this.zhagangStatusY = false;
                     }else if(_this.PressureData.zhagang.current<_this.BaselineData.zhagang.minVal){
                         _this.zhagangStatus = false;
                         _this.zhagangStatusY = true;
                     };
                     if(_this.PressureData.other.current>_this.BaselineData.other.maxVal){
                         _this.otherStatus = true;
                         _this.otherStatusY = false;
                     }else if(_this.PressureData.other.current<_this.BaselineData.other.minVal){
                         _this.otherStatus = false;
                         _this.otherStatusY = true;
                     };
                     /*if((_this.PressureData.guolu.current>_this.BaselineData.guolu.maxVal)||(_this.PressureData.guolu.current<_this.BaselineData.guolu.minVal)){
                         _this.guoluStatus = true;
                     }else{
                         _this.guoluStatus = false;
                     }*/
                 }


			};
        	var error = function(e){
        		console.log('加载压力出错')
			}
           this.$http.get(URL+'/quanwang/equipment/status').then(success,error)
		},
        /*消息中心*/
        getMsgCenter:function(){
            var _this=this;
            bus.$on('msgType',function(val){
                _this.msgType=val;
            });
            var success=function(res){
                _this.msgCenter=res.data;
               // console.log(_this.msgCenter)
            };
            var error=function(e){
                console.log('全网消息中心出错了');
            };
            this.$http(URL+'/message/current').then(success,error);
        },
        waveChart:function(){
            /*波动归因*/
            Chart3('gas_chart',URL+'/coalgas/quanwang/bodongguiyin');
        },
        getJson:function(){
            var _this=this;
            this.$http.get(URL+'/quanwang/gaolu/prediction').then(function(res){
                _this.gasData.gaolu  = res.data[res.data.length-1][1];
                //console.log(this.gasData.gaolu);
            });
            this.$http.get(URL+'/quanwang/refenglu/prediction').then(function(res){
                _this.gasData.refenglu  = res.data[res.data.length-1][1];
            });
            this.$http.get(URL+'/quanwang/zhagang/prediction').then(function(res){
                _this.gasData.zhagang  = res.data[res.data.length-1][1]
            });
            this.$http.get(URL+'/quanwang/other/prediction').then(function(res){
                _this.gasData.other  = res.data[res.data.length-1][1]
            });
            this.$http.get(URL+'/quanwang/guolu/prediction').then(function(res){
                _this.gasData.guolu  = res.data[res.data.length-1][1]
            });

        },
        getTimeStamp:function(){
            var _this=this;
            var success=function(res){
                _this.timeStamp=res.data.time;
                //console.log(res.data);
            };
            var error=function(e){
                console.log('加载时间戳出错了');
            };

            this.$http.get(URL+'/time/getTime').then(success,error);
        },
        getName:function(){
            var _this=this;
            var success=function(res){
                _this.username=res.data.username;
                //console.log(res.data);
            };
            var error=function(e){
                console.log('加载用户名出错了');
            };
            this.$http.get(URL+'/system/getuserinfo').then(success,error);
        }

    }
});
// APP.http.headers.common['Authorization'] = 'Basic YXBpOnBhc3N3b3Jk';
//APP.http.headers.common['Cookie'] = 'SESSION=c25803d9-eb82-4d62-ba23-2f10b50f7122';

